package com.ler.yrmall.cart.controller;

import com.ler.yrmall.cart.service.CartService;
import com.ler.yrmall.basic.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author leron
 */
@RestController
@RequestMapping("/cart")
public class CartController {

    @Resource
    private CartService cartService;

    @PostMapping("/add")
    public Result<?> addCart(long skuId, int num) {
        cartService.addCart(skuId,num);
        return Result.ok();
    }

    @GetMapping
    public Result<?> get() {
        return Result.ok(cartService.getCartList());
    }

    @GetMapping("/checkedChange")
    public Result<?> checkedChange(long skuId) {
        cartService.checkedChange(skuId);
        return Result.ok();
    }

    @GetMapping("/checkAllChange")
    public Result<?> checkAllChange() {
        cartService.checkAllChange();
        return Result.ok();
    }

    @GetMapping("/delete/{skuId}")
    public Result<?> delete(@PathVariable Long skuId) {
        cartService.deleteCartItem(skuId);
        return Result.ok();
    }

}
